package com.example.xinli.service.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.xinli.dao.JiazhishouceMapper;
import com.example.xinli.dao.JienalianxiMapper;
import com.example.xinli.domain.entity.Jiazhishouce;
import com.example.xinli.domain.entity.Jienalianxi;
import com.example.xinli.domain.vo.JiazhishouceSubmitVo;
import com.example.xinli.domain.vo.JienalianxiSubmitVo;
import com.example.xinli.domain.vo.ResponseBean;
import com.example.xinli.domain.vo.ResponseBeanEnum;
import com.example.xinli.service.IJiazhishouceService;
import com.example.xinli.service.IJienalianxiService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class JienalianxiServiceImpl extends ServiceImpl<JienalianxiMapper, Jienalianxi> implements IJienalianxiService {

    @Autowired
    JienalianxiMapper jienalianxiMapper;

    @Override
    public ResponseBean getAllUserJienalianxi(String userId) {
        QueryWrapper<Jienalianxi> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", userId);
        List<Jienalianxi> jienalianxiList = jienalianxiMapper.selectList(queryWrapper);
        return ResponseBean.success(jienalianxiList);
    }

    @Override
    public ResponseBean submitJienalianxi(JienalianxiSubmitVo jienalianxiSubmitVo) {
        Jienalianxi jienalianxi = new Jienalianxi();
        jienalianxi.setUserId(jienalianxiSubmitVo.getUserId());
        jienalianxi.setDate(jienalianxiSubmitVo.getDate());
        jienalianxi.setName(jienalianxiSubmitVo.getName());
        jienalianxi.setQingjing(jienalianxiSubmitVo.getQingjing());
        jienalianxi.setGanshou(jienalianxiSubmitVo.getGanshou());
        jienalianxi.setXingdong(jienalianxiSubmitVo.getXingdong());
        jienalianxi.setZhidao(jienalianxiSubmitVo.getZhidao());
        jienalianxi.setGaosu(jienalianxiSubmitVo.getGaosu());
        jienalianxi.setRecordId(-1);

        int res = jienalianxiMapper.insert(jienalianxi);
        if (res > 0) {
            return ResponseBean.success();
        }
        return ResponseBean.error(ResponseBeanEnum.ERROR);
    }
}

